<?
global $db;

inc_inclib("upload.php");

$file = upload_getfile($params["name"]);

global $magickdir,$topdir;

#$cmd = "$magickdir/convert ".escapeshellarg($file["tmp_name"]). " ".escapeshellarg("$topdir/shots/{$this->id}.jpg");
#`$cmd`;

if ($file["size"] == 0) return;


$fname = $file["tmp_name"];
list($w,$h,$t,$a) = getimagesize($fname);
if (!in_array($t,array(IMAGETYPE_GIF,IMAGETYPE_JPEG,IMAGETYPE_PNG))) { fusedie("image does not support the image type of $fname"); }

$exts = array(
	IMAGETYPE_GIF=>"gif",
	IMAGETYPE_JPEG=>"jpg",
	IMAGETYPE_PNG=>"png",
	);
$ext = $exts[$t];

#inc_incfile("image.php");
#$img = _image_load($file["tmp_name"]);
#_image_save($img,"$topdir/shots/{$this->id}.png");

copy($fname,"$topdir/shots/{$this->id}.$ext");

$e = array(
	"id"=>$this->id,
	"{$params["name"]}"=>"{$this->id}.$ext",
	);

$db->autoquery("update",$this->table,$e);
?>